﻿<Window x:Class="Robert.BlogUpdater.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Feed Tracker" 
        Height="400" MinHeight="{Binding ElementName=feedTextList, Path=ActualHeight}"
        Width="800" MinWidth="{Binding ElementName=feedTextList, Path=ActualWidth}"
        Closing="Window_Closing">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.Resources>
            <DataTemplate x:Key="feedTitle">
                <StackPanel>
                    <TextBlock Text="{Binding Path=FeedTitle}">
                        <TextBlock.ToolTip>
                            <TextBlock Text="{Binding Path=FeedURL}"/>
                        </TextBlock.ToolTip>
                    </TextBlock>
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="feedSummary">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{Binding ElementName=feedTextList, Path=ActualWidth}"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0"
                               FontWeight="Bold" 
                               FontSize="16" TextWrapping="Wrap"
                               Text="{Binding Path=PostTitle}"/>
                    <TextBlock Grid.Row="1"
                               Text="{Binding Path=PostSummary}"
                               TextWrapping="WrapWithOverflow"/>
                    <TextBlock Grid.Row="3"
                               Text="{Binding Path=PostDate,StringFormat='Published on: {0}'}"/>
                    <TextBlock Grid.Row="2">
                        <Hyperlink NavigateUri="{Binding Path=PostURL}" Click="Hyperlink_Click">
                            <Hyperlink.ToolTip>
                                <TextBlock>Open link in web browser.</TextBlock>
                            </Hyperlink.ToolTip>
                            <TextBlock Text="Read the rest of this entry..."/>
                        </Hyperlink>
                    </TextBlock>
                </Grid>
            </DataTemplate>
        </Grid.Resources>
        <StackPanel Orientation="Horizontal"
                    Grid.Row="0" Grid.Column="0"
                    Grid.ColumnSpan="2" Margin="3">
            <TextBlock Text="Enter Feed:"
                       Margin="3,0,3,0"
                       VerticalAlignment="Center"/>
            <TextBox x:Name="feedAddress"
                     Margin="3,0,3,0"
                     MaxWidth="350" MinWidth="350"
                     VerticalAlignment="Center"
                     ToolTip="Enter your RSS 2.0 Feed address here." KeyDown="isEnterHit" />
            <Button x:Name="getFeed"
                    Margin="3,0,3,0" Padding="4"
                    Click="getFeedClick" >
                <StackPanel>
                    <TextBlock Text="Get feed!"/>
                    <ProgressBar x:Name="progressBar"
                         Width="50" Height="9"/>
                </StackPanel>
            </Button>
        </StackPanel>
        <Grid Grid.Row="1" Grid.Column="0"
              Margin="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="{Binding ElementName=removeFeed, Path=Height}"/>
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" Text="Feed List:"
                       Margin="3,0,3,3"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Top"/>
            <ListBox x:Name="feedList" 
                     Grid.Row="1"
                     Margin="3,0,3,3" ScrollViewer.VerticalScrollBarVisibility="Auto"
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Stretch"
                     ItemsSource="{Binding}" 
                     ItemTemplate="{StaticResource feedTitle}" SelectionChanged="feedSelected">
            </ListBox>
            <Button x:Name="removeFeed"
                    Grid.Row="2"
                    Margin="3,0,3,3" Padding="4"
                    HorizontalAlignment="Left" 
                    VerticalAlignment="Bottom"
                    Content="Remove feed" 
                    Click="removeFeed_Click"></Button>
        </Grid>
        <ListBox x:Name="feedTextList" 
                 Grid.Row="1" Grid.Column="1" Margin="0,0,6,6"
                 ItemsSource="{Binding}"
                 ItemTemplate="{StaticResource feedSummary}"
                 ScrollViewer.VerticalScrollBarVisibility="Hidden"
                 ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                 ScrollViewer.CanContentScroll="False">
        </ListBox>
    </Grid>
</Window>
